<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/8/20
  Time: 9:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>商城</title>
</head>
<script>
    function updateGoods(id) {
        window.location.href="${pageContext.request.contextPath}/goods/toUpdate?id="+id;
    }

    function deleteGoods(id) {
        window.location.href="${pageContext.request.contextPath}/goods/delete?id="+id;
    }

    function addCar(id) {
        window.location.href="${pageContext.request.contextPath}/goods/addCar?id="+id;
    }

    function addGoods() {
        window.location.href="${pageContext.request.contextPath}/goods/toAdd";
    }

    function toBuy() {
        window.location.href="${pageContext.request.contextPath}/goods/toCar";
    }

    function toLogin() {
        window.location.href="${pageContext.request.contextPath}/login.jsp";
    }

    function logout() {
        window.location.href="${pageContext.request.contextPath}/user/logout";
    }
</script>
<body>
    <div style="text-align: right">
        <c:if test="${user!=null}">
            ${user.userName}
        </c:if>
        <c:if test="${user==null}">
            <a href="#" onclick="toLogin()">登录</a>
        </c:if>
        |<a href="#" onclick="logout()">注销</a>
    </div>
    <c:if test="${isAdmin}"><a href="#" onclick="addGoods()">添加商品</a> </c:if>
    <table>
        <thead>
            <tr>
                <td>商品名称</td>
                <td>商品标题</td>
                <td>商品类型</td>
                <td>商品描述</td>
                <td>商品价格</td>
                <td>商品数量</td>
            </tr>
        </thead>
        <c:forEach items="${goodsList}" var="goods">
            <tr>
                <td>${goods.name}</td>
                <td>${goods.title}</td>
                <td>${goods.goodsType.name}</td>
                <td>${goods.describe}</td>
                <td>$ ${goods.price} 元</td>
                <td>剩余 ${goods.quantity} 件</td>
                <c:if test="${isAdmin}"><td><a href="#" id="updateBtn" onclick="updateGoods(${goods.id})">修改商品</a></td></c:if>
                <c:if test="${isAdmin}"><td><a href="#" id="deleteBtn" onclick="deleteGoods(${goods.id})">删除商品</a></td></c:if>
                <td><a href="#" id="addCar" onclick="addCar(${goods.id})">添加购物车</a> </td>
            </tr>
        </c:forEach>
    </table>
    <a href="#" onclick="toBuy()">结算</a>
</body>
</html>
